<?php
class XPHP_DB_Factory
{
	public $server;
	public $dbname;
	public $username;
	public $password;
	
	public $connect;
	
	public function __construct($server, $dbname, $username, $password)
	{
		$this->server = $server;
		$this->dbname = $dbname;
		$this->username = $username;
		$this->password = $password;

		$this->connect = mysql_connect($this->server, $this->username, $this->password,true);		
		if (mysql_errno() == 1203)
		{
			header('Error');
			exit;
		} 
		elseif (mysql_errno() == 1045)
		{
			die('Can not connection to database server');	
		}
		
		if (!$dbselect = @mysql_select_db($this->dbname,$this->connect))
		{
			$this->connect = @mysql_select_db($this->dbname,$this->connect) or die("Can not find database");
		}	
		
	}
	
	public function setDefaultDBFactory()
	{
		require_once 'XPHP/Registry.php';
		XPHP_Registry::set("DefaultDBFactory", $this);
	}
	
	public function close()
	{
		if ($this->connect)
			return mysql_close($this->connect);
		else
			return false;
	}
}